import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import Vuex from 'vuex'
import store from './store'
// 导入进度条
import Nprogress from 'nprogress'
// 导入进度条样式
import 'nprogress/nprogress.css'
// 导入富文本
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

import common from './common'
Vue.prototype.common = common

// 默认请求地址
axios.defaults.baseURL = 'http://maicaii.cn/index.php'

axios.interceptors.request.use(config => {
        Nprogress.start()
        return config
    })
    //相应结束的时候隐藏进度条
axios.interceptors.response.use(config => {
    Nprogress.done()
        //必须返回config
    return config
})

// axios.defaults.baseURL = 'http://localhost:3030/admin/api'

Vue.prototype.$http = axios
Vue.config.productionTip = false

Vue.use(ElementUI)
Vue.use(mavonEditor)

router.beforeEach((to, from, next)=>{
	// console.log(to)
	// console.log(from)
	// console.log(next)
	// next()
	// 先检测储存的信息是否过期,没有过期在检测登陆状态
	var getItemValue = common.getItem(store.state.loginTime.startTime,store.state.loginTime.expires)
	console.log('是否过期方法getItem:'+JSON.stringify(getItemValue))
	console.log('在路由调时间'+JSON.stringify(store.state.loginTime))
	console.log('路由拦截登陆状态检测：'+store.state.isLogin) //
	// console.log('token:'+store.state.token)
	// console.log('userinfo:'+JSON.stringify(store.state.userinfo))
	if(store.state.isLogin){ // 如何登陆状态为False就跳转登录页
		if(getItemValue === false){ //false过期
			//过期做点什么
			next('/Login')
		}else{
			//不过期做点什么
			next()
		}
	}else{
		if(to.path === '/Login'){ // 不登录进入的登陆页
			next()
		}else{
			next('/Login')
		}
	}
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
